package com.xy.servicemanage.service.impl;
import java.util.List;

import com.ruoyi.common.core.domain.servicemanage.ServiceShow;
import com.ruoyi.common.core.mapper.servicemanager.ServiceShowMapper;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.xy.servicemanage.service.IServiceShowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 服务显示信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@Slf4j
@Service
public class ServiceShowServiceImpl implements IServiceShowService
{
    @Autowired
    private ServiceShowMapper serviceShowMapper;

    /**
     * 查询服务显示信息
     *
     * @param id 服务显示信息主键
     * @return 服务显示信息
     */
    @Override
    public ServiceShow selectServiceShowById(Long id)
    {
        return serviceShowMapper.selectServiceShowById(id);
    }

    /**
     * 新增服务显示信息
     *
     * @param serviceShow 服务显示信息
     * @return 结果
     */
    @Override
    public int insertServiceShow(ServiceShow serviceShow)
    {
        return serviceShowMapper.insertServiceShow(serviceShow);
    }

    /**
     * 修改服务显示信息
     *
     * @param serviceShow 服务显示信息
     * @return 结果
     */
    @Override
    public int updateServiceShow(ServiceShow serviceShow)
    {
        return serviceShowMapper.updateServiceShow(serviceShow);
    }

    /**
     * 逻辑删除(修改状态)
     * @param id
     * @return
     */
    @Log(title = "服务显示信息", businessType = BusinessType.DELETE)
    @Transactional
    @Override
    public int deleteServiceShowById(Long id,  int deleted) {
        ServiceShow serviceShow = serviceShowMapper.selectServiceShowById(id);
        if (serviceShow == null) {
            throw new RuntimeException("服务显示信息不存在");
        }
        serviceShow.setDeleted(deleted);
        int rowsAffected = serviceShowMapper.updateServiceShow(serviceShow);
        if (rowsAffected == 0) {
            throw new RuntimeException("并发冲突：该记录已被其他用户修改");
        }
        return rowsAffected;
    }

}
